package com.example.sp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.sp.entity.StuGrade;
import com.example.sp.service.StuGradeService;
import com.example.sp.service.StuInfoService;
import com.example.sp.utils.Res;
import com.example.sp.utils.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.RowBounds;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/grade")
@AllArgsConstructor
@Slf4j
public class StuGradeController{
    private final StuGradeService stuGradeService;
    private final StuInfoService stuInfoService;

    /**
     * 前十
     * @return7
     */
    @RequestMapping("/top")
    public Result Top(){

        return Res.ok(stuGradeService.listMaps(new QueryWrapper<StuGrade>().select("stu_name as 'name'",
                "sum(grade) as 'zf'").eq("stu_trem","2018-2019第一学期").groupBy("stu_name")
        .orderByDesc("sum(grade)").last("limit 10")));
    }


    @RequestMapping("/newb")
    public Result newb(){
        return Res.ok(stuGradeService.listMaps(new QueryWrapper<StuGrade>().select("stu_no","stu_name",
                "colleage","profession","sum(jsjzcyl)+SUM(jsjzyyy)+SUM(ydyykfjs)+SUM(rjgc)+SUM(zgjdsgy)+SUM(WebService) as grade",
                "jsjzcyl","jsjzyyy","ydyykfjs","rjgc","zgjdsgy","WebService").groupBy("stu_name").orderByDesc("grade").last("limit 10")));
    }
    @RequestMapping("/newd")
    public Result newd(String stuname){
        return Res.ok(stuGradeService.listMaps(new QueryWrapper<StuGrade>().select("stu_no","stu_name",
                "colleage","profession","sum(jsjzcyl)+SUM(jsjzyyy)+SUM(ydyykfjs)+SUM(rjgc)+SUM(zgjdsgy)+SUM(WebService) as grade",
                "jsjzcyl","jsjzyyy","ydyykfjs","rjgc","zgjdsgy","WebService").eq("stu_name",stuname)));
    }

}
